import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";

import Hot from "../pages/hot/Index.vue";
import Cinema from "../pages/cinema/Index.vue";
import Wait from "../pages/wait/Index.vue";
import Wait2 from "../pages/wait/Index2.vue";
import Classic from "../pages/classic/Index.vue";
import Detail from "../pages/detail/Index.vue";
import NotFound from "../pages/notfound/Index.vue";

import YesToday from "../pages/hot/yestoday/Index.vue";
import Today from "../pages/hot/today/Index.vue";

// 创建了路由实例
// vue的路由默认是精准匹配
// 默认是排他性路由, react的5版本路由是包容性路由
const router = createRouter({
  // 路由模式
  // hash模式，带#
  // 如果项目打包完放到服务器，hash不会有任何问题，history模式刷新页面会404
  history: createWebHashHistory(import.meta.env.BASE_URL),
  // history模式，不带#
  // history: createWebHistory(import.meta.env.BASE_URL),
  // 美观

  // abstract模式
  // app里面的模式
  routes: [
    // 重定向
    {
      path: "/",
      // redirect: "/hot/yestoday",
      redirect: "/hot",
    },
    {
      path: "/hot",
      component: Hot,
      // children表示的是下一级路由，语法和routes完全相同
      children: [
        {
          path: "/hot",
          redirect: "/hot/yestoday",
        },
        {
          path: "/hot/yestoday",
          component: YesToday,
        },
        {
          path: "today",
          component: Today,
        },
      ],
    },
    {
      path: "/cinema",
      component: Cinema,
    },
    {
      path: "/wait",
      // component: Wait,
      // 命名路由, 要将component换成components
      // 在页面里面需要给routerView组件添加name属性
      components: {
        a: Wait,
        b: Wait2,
      },
    },
    {
      // alias表示别名
      path: "/classic",
      component: Classic,
      alias: "/jingdian",
    },
    {
      // 动态路由
      // 通过url的跳转的传参
      // 后面加？表示动态可选路由
      path: "/detail/:id?",
      component: Detail,
      name: "detail",
      // props: true加上以后就可以在组件里面直接使用props来接受动态参数了
      props: true,
    },
    {
      // 404页面
      // 写在整个路由表的最下面
      path: "/:pathMatch(.*)*",
      component: NotFound,
    },
  ],
});

export default router;
